package com.school.gift.controller.admin;

import com.github.pagehelper.PageInfo;
import com.school.gift.domain.Evaluate;
import com.school.gift.model.EvaluateModel;
import com.school.gift.service.EvaluateService;
import com.school.support.base.AdminBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import zhibi.common.support.base.Page;
import zhibi.common.support.exception.MessageException;
import zhibi.common.support.mybatis.example.Example;
import zhibi.common.support.mybatis.example.ExampleUtil;

import java.util.Date;

/**
 * Created by 执笔 on 2017/3/22.
 */
@Controller
@RequestMapping("admin/evaluate")
public class MEvaluateController extends AdminBaseController {

    @Autowired
    private EvaluateService evaluateService;


    @RequestMapping("list")
    public String list(Model model, Page page){
        Example example = ExampleUtil.getInstance()
                .addOrder("addtime")
                .getExample();
        PageInfo<EvaluateModel> pageInfo = evaluateService.selectModel(example,page);
        setModelAttribute(model,pageInfo);
        return "admin/evaluate/list";
    }

    @RequestMapping("save")
    public String save(Evaluate evaluate){
        Evaluate temp = evaluateService.selectByPK(evaluate.getId());
        if(temp == null){
            throw new MessageException("该评论不存在，不能回复");
        }
        evaluate.setReplytime(new Date());
        evaluateService.updateByIdSelective(evaluate);
        return refresh();
    }
}
